<template>
<div>
    <Row :gutter="8" type="flex" align="middle">
        <Col>
            <TreeSelect v-model="tags_id" transfer multiple :data="selflist" placeholder="请选择个人标签" v-width="200" @on-change="changetag"/>
        </Col>
        {{currentTab}}
        <!-- <Col>
            <Select v-model="tags_id" v-width="200" multiple placeholder="请选择个人标签" filterable @on-change="changetag">
                <OptionGroup :label="item.label" v-for="item in selflist" :key="item.value">
                    <Option v-for="it in item.children" :value="it.value" :key="it.value">{{ it.label }}</Option>
                </OptionGroup>
            </Select>
        </Col> -->
        <Col>
            <Select v-model="project_tags_id" v-width="200" multiple placeholder="请选择部门标签" @on-change="changetag">
                <Option v-for="item in projectlist" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
        </Col>
    </Row>
</div>
</template>

<script>
    import { patientindextagsconditionlistv2 } from '@/api/hqapi/tags';
    import util from '@/libs/util';
    export default {
        components: { },
        props: ["currentTab"],
        name: 'diagnosis',
        data () {
            return {
                tags_id: [],
                project_tags_id: [],
                params: { tags_ids: [], project_tags_ids: [] ,type:''},
                selflist: [],
                projectlist: []
            };
        },
        mounted () {
            // this.params.tags_ids = this.tags_ids.split(',')
            // this.params.project_tags_ids = this.project_tags_ids.split(',')
             if(this.currentTab=='add'){
                   this.initial();
                }
        },
            
        methods: {
            initial () {
                // console.log('111')
                 if(this.currentTab=='add'||this.currentTab=='ordered'){
                    this.askData()
                }
            },
            askData () {
                // let data = window.sessionStorage.getItem('selflist')
                // if (data) {
                //     let datas = JSON.parse(data)
                //     this.selflist = []
                //     this.projectlist = datas.project_tags
                //     for (let item of datas.self_tags) {
                //         Object.assign(item, { disabled: true })
                //         if (item.value == util.cookies.get('uuid')) {
                //             item.expand = true
                //             this.selflist.unshift(item)
                //         } else {
                //             this.selflist.push(item)
                //         }
                //     }
                // } else {
                    patientindextagsconditionlistv2().then(res => {
                        let data = JSON.stringify(res)
                        window.sessionStorage.setItem('selflist', data)
                        // this.selflist = res.self_tags
                        this.selflist = []
                        this.projectlist = res.project_tags
                        for (let item of res.self_tags) {
                            Object.assign(item, { disabled: true })
                            if (item.value == util.cookies.get('uuid')) {
                                item.expand = true
                                this.selflist.unshift(item)
                            } else {
                                this.selflist.push(item)
                            }
                        }
                    })
              
                // }
            },
            changetag () {
                this.params = { tags_ids: this.tags_id.join(','), project_tags_ids: this.project_tags_id.join(',') }
                this.$emit('sunchangetag', this.params)
            }
        }
    };
</script>
